/** 选择图片 */
export function myChooseImage(data: {
  count?: number;
  sourceType?: ('album' | 'camera')[];
  sizeType?: ('compressed' | 'original')[];
  camera?: 'back' | 'front';
}): Promise<UniApp.ChooseImageSuccessCallbackResult> {
  return new Promise<UniApp.ChooseImageSuccessCallbackResult>((resolve, reject) => {
    // #ifdef MP-WEIXIN
    uni.chooseMedia({
      count: data.count || 1,
      mediaType: ['image'],
      sizeType: data.sizeType || ['compressed', 'original'],
      sourceType: data.sourceType || ['album', 'camera'],
      camera: data.camera,
      success(res) {
        const tempFilePaths = res.tempFiles.map((item) => item.tempFilePath);
        const tempFiles = res.tempFiles.map((item) => {
          return { size: item.size, path: item.tempFilePath };
        });
        resolve({ tempFilePaths, tempFiles });
      },
      fail(err) {
        reject(err);
      },
    });
    // #endif

    // #ifndef MP-WEIXIN
    uni.chooseImage({
      count: data.count || 1,
      sizeType: data.sizeType || ['compressed', 'original'],
      sourceType: data.sourceType || ['album', 'camera'],
      success(res) {
        resolve({ tempFilePaths: res.tempFilePaths, tempFiles: res.tempFiles });
      },
      fail(err) {
        reject(err);
      },
    });
    // #endif
  });
}
